//index.js
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var config = require('../../config')
var util = require('../../utils/util.js')

Page({
    data: {
        userInfo: {},
        topics: [],
        page:0,
        scrollHeight: 0,
        hasMore:true,
        loadding:false,
    },
    onLoad: function () {
      console.log('onLoad')
      var that = this
      wx.getSystemInfo({
        success: function (res) {
          console.info(res.windowHeight);
          that.setData({
            scrollHeight: res.windowHeight
          });
        }
      }); 
      //调用应用实例的方法获取全局数据
      that.getTopics(that)
    },
    bindDownLoad: function (e) {
      console.log(e)
      var that = this;
      that.getTopics(that);
    },

    getTopics: function (that) {

      var options = {
        url: config.service.requesTopicstUrl,
        data: {
          'page[number]': that.data.page+1,
          'page[size]': 12,
          'agg[size]': -1,
          'filter[channel]': 86
        },
        success(result) {
          const {data,meta} = result.data
          that.setData({
            topics: that.data.topics.concat(data),
            page: that.data.page + 1,
            hasMore: !meta.last,
            loadding:false,
          })
        },
        fail(error) {
          util.showModel('请求失败', error);
          console.log('request fail', error);
          that.setData({
            loadding: false,
          })
        }
      }
      that.setData({
        loadding: true,
      })
      wx.request(options)
    },
    toDetailsTap: function (e) {
      wx.navigateTo({
        url: "/pages/topic/topic?id=" + e.currentTarget.dataset.id
      })
    },
})
